package app

import (
	"log"
	"os"
	"strconv"
)

type Env struct {
	S Storage
}

func GetEnv() *Env {
	addr := os.Getenv("APP_REDIS_ADDR")
	if addr == "" {
		addr = "127.0.0.1:6380"
	}
	passwd := os.Getenv("APP_REDIS_PASSWD")
	if passwd == "" {
		passwd = "qweasd"
	}

	dbS := os.Getenv("APP_REDIS_DB")
	if dbS == "" {
		dbS = "1"
	}

	db, err := strconv.Atoi(dbS)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("addr:%s,password:%s,db:%d\n", addr, passwd, db)

	r := NewRedisCli(addr, passwd, db)
	return &Env{
		S: r,
	}
}
